﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SWS.PIP.CMD
{
	public partial class ProgressBarDlg : Form
	{
		int mPanleBottomInitHeight = 0;

		public ProgressBarDlg()
		{
			InitializeComponent();

			mPanleBottomInitHeight = panel_Bottom.Height;
		}

		private void ProgressBarDlg_FormClosed(object sender, FormClosedEventArgs e)
		{
			if (this.Owner != null)
			{
				this.Owner.Visible = true;
			}
		}

		private void button_More_Click(object sender, EventArgs e)
		{
			if (panel_Bottom.Visible == true)
			{
				panel_Bottom.Visible = false;

				this.Height -= panel_Bottom.Height;

				button_More.Text = "收起";
			}
			else
			{
				panel_Bottom.Visible = true;
				//panel_Bottom.Height = mPanleBottomInitHeight;
				this.Height += mPanleBottomInitHeight;

				button_More.Text = "详细...";
			}
		}

		public void Init(string sTitle = "")
		{
			progressBar.Value = 0;

			if (panel_Bottom.Visible == false)
			{
				button_More.PerformClick();
			}

			if (sTitle != "")
			{
				label_Process.Text = sTitle;
			}
		}

		public void SetProgressValue(int value)
		{ 
			if (value >= 100)
			{
				progressBar.Value = 100;
			}
			else if (value <=0)
			{
				progressBar.Value = 0;
			}
			else
			{
				progressBar.Value = value;
			}
			this.Update();
		}

		public void SetProgressPercent(double percent)
		{
			if (percent <= 100 && percent >=0)
			{
				SetProgressValue((int)percent);
			}
		}

		public void SetTitle(string sTitle)
		{
			label_Process.Text = sTitle;
			this.Update();
		}

		public void WriteLog(string sMsg)
		{
			if (sMsg != "")
			{
				this.richTextBox_log.AppendText(DateTime.Now.ToString() + ", " + sMsg + "\n");
			}
		}
	}
}
